#include <51func.h>
int setNonblock(int fd){
    int open_flag = fcntl(fd,F_GETFL);
    open_flag = open_flag|O_NONBLOCK;
    int ret = fcntl(fd,F_SETFL,open_flag);
    ERROR_CHECK(ret,-1,"fcntl");
    return 0;
}
int main(int argc, char *argv[])
{
    // ./2_aqiang 192.168.118.128 1234
    ARGS_CHECK(argc,3);
    int sockfd = socket(AF_INET,SOCK_STREAM,0);
    struct sockaddr_in addr;//赋值使用的 struct sockaddr_in
    addr.sin_family = AF_INET;
    addr.sin_port = htons(atoi(argv[2]));
    addr.sin_addr.s_addr = inet_addr(argv[1]);
    // 传参 先取地址 再强转
    int ret = connect(sockfd,(struct sockaddr *)&addr,sizeof(addr));
    ERROR_CHECK(ret,-1,"connect");

    setNonblock(sockfd);
    char buf[3];
    while(1){
        bzero(buf,sizeof(buf));
        ssize_t sret = recv(sockfd,buf,2,0);
        printf("sret = %ld, buf = %s\n", sret, buf);
        sleep(1);
    }
    return 0;
}

